{extend name="common/base"}
{block name="content"}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">轮播图列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success" onclick="location='{:url('insert')}'">
                                        <span class="am-icon-plus"></span> 新增</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-6">
                        <form action="{:url('index')}">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input type="text" class="am-form-field " name="search">
                            <span class="am-input-group-btn">
                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="submit"></button>
                             </span>
                        </div>
                        </form>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                            <tr>
                                <th>轮播图缩略图</th>
                                <th>轮播图跳转地址</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="ajax-wrapper">

                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                            <div class="am-fr ajax-page">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}
{block name="footer-js"}
<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">Amaze UI</div>
        <div class="am-modal-bd">
            你，确定要删除这条记录吗？
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" >取消</span>
            <span class="am-modal-btn confirm">确定</span>
        </div>
    </div>
</div>
<script src="__ADMIN__/template.js"></script>
<script id="ajax-content" type="text/html">
    <%for(var i = 0 ; i<data.length; i++) {%>
    <tr data-id="<%=data[i].id%>">
        <td><img src="__THUMBS__<%=data[i].src%>"  class="tpl-table-line-img" alt=""></td>
        <td><%=data[i].url%></td>
        <td><%=data[i].ord%></td>
        <td>
            <a href="{:url('edit')}?id-<%=data[i].id%>" class="tpl-table-black-operation">
                <i class="am-icon-pencil"></i> 编辑
            </a>
            <a href="javascript:;" class="tpl-table-black-operation-del del-btn" >
                <i class="am-icon-trash"></i> 删除
            </a>
        </td>
    </tr>
    <%}%>
</script>
<script>



    var config = {
        success : function (res) {
            console.log(res)
            var html = template($('#ajax-content').html() , {data:res.ad_list.data})

            $('#ajax-wrapper').html(html)
            $('.ajax-page').html(res.page)
        }
    };
    $.ajax(config);
    $('.ajax-page').on('click' , 'a' , function (e) {
        e.preventDefault();
        var url = $(this).attr('href');
        config.url = url;
        $.ajax(config);
    })

    $('#ajax-wrapper').on('click' , '.del-btn'  , function (e) {
        $('#my-confirm').modal();
        var id = $(this).parent().parent().data('id');
        $('.confirm').click(function () {
            $.ajax({
                url : '{:url("delete")}?id='+id,
                success : function (res) {
                    $.ajax(config);
                }
            });
        });


    });

</script>
{/block}